<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class captcha_model extends WST_Model {
	private $_table = "post_bad";

	function __contruct(){
        parent::__construct();

    }

    function make_captcha(){
        $this->load->helper('captcha');
        $vals = array(
            'img_path'  => './tmp/captcha/',
            'img_url'  => base_url().'tmp/captcha/',
            'img_width'  => 80,
            'img_height' => 27,
            'font_path'=>'tmp/captcha/fonts/impact.ttf'
        );
        $cap = create_captcha($vals);
        $data = array(
            'captcha_time' => $cap['time'],
            'ip_address' => $this->input->ip_address(),
            'word' => strtolower($cap['word'])
        );
        $this->session->set_userdata($data);
        return $cap['image'];
    }


	public function save($data, $id = FALSE) {

        if ($id == FALSE) {

            // This is an insert
            $this->db->insert($this->_table,$data);
        }
        else {

            // This is an update
            $filter = $this->primaryFilter;
			$this->db->where($this->primary_key, $filter($id));
			$this->db->update($this->_table, $data);
        }
        // Return the ID
        return $id == FALSE ? $this->db->insert_id() : $id;
    }
}